//
//  TabControllersManager.m
//  DriftDog
//
//  Created by rimi on 15/9/7.
//  Copyright (c) 2015年 廖马林. All rights reserved.
//

#import "TabControllersManager.h"

@interface TabControllersManager ()

@end

@implementation TabControllersManager

+ (TabControllersManager *)sharedManager {

    static TabControllersManager *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        manager = [[TabControllersManager alloc] init];
    });
    return manager;
}

#pragma mark - getter

- (UINavigationController *)rootViewController {

    if (!_rootViewController) {
        
        _rootViewController = [[UINavigationController alloc] init];
        _rootViewController.navigationBarHidden = YES;
    }
    return _rootViewController;
}

- (LMLTabViewController *)mainTabController {

    if (!_mainTabController) {
        
        // 使用运行时
        NSArray *controllerClassName = @[@"HomeViewController", @"PostNoteViewController", @"ChatViewController", @"PersonalViewController"];
        NSMutableArray *viewControllers = [NSMutableArray arrayWithCapacity:0];
        [controllerClassName enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            
            Class class = NSClassFromString(obj);
            UIViewController *controller = [[class alloc] init];
            [viewControllers addObject:controller];
        }];
        _mainTabController = ({
        
            LMLTabViewController *controller = [[LMLTabViewController alloc] initWithViewControllers:viewControllers];
            controller;
        });
    }
    return _mainTabController;
}

@end
